<?php

namespace App\Providers;

use App\Http\Middleware\SupplierDomainMiddleware;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Recharge\Logic\ApiNotifyLogic;
use Illuminate\Support\ServiceProvider;
use App\Models\Admin\SupplierConfiguration;

class SupplierServiceProvider extends ServiceProvider
{
    /**
     * Register services.
     */
    public function register(): void
    {
        //
    }

    /**
     * Bootstrap services.
     */
    public function boot(): void
    {
        $this->apiRouter();
        // 供应商注册数据库配置
        SupplierConfiguration::registerDbConnectAll();
    }

    /**
     * @return void
     */
    public function apiRouter(): void
    {
        Route::middleware([SupplierDomainMiddleware::class])->group(function () {
            // api回调
            Route::any('/notify/{en}', fn (Request $request, string $en) => ApiNotifyLogic::new($request, $en)->send());
        });
    }
}
